<?php
/**
 * huhaiqin,2024.10.13
 * 游戏模块客户端对外接口
 */
namespace Game\Controller;

class ApiController extends \Common\Controller\BaseController{
    
    /**
     * huhaiqin,2024.10.13
     * 发送短信的接口
     */
    public function send_sms_yuyue(){
        $check = D('GameYuyueUser')->_get_done(I('mobile'),I('pid'));
        if($check){
            _apiReturn(0,'done'); //已经预约了
        }
        $type = I('yuyue') ? I('yuyue') : 'yuyue-game'; //给未来留点口子
        D('Sms')->send_sms(I('mobile'),I('s'),$type);
    }

   
    /**
     * huhaiqin,2024.10.13
     * 校验验证码
     */
    public function check_sms_yuyue_code(){
        $checkYuyue = D('GameYuyue')->find(I('pid')); //检测上传的预约是否存在
        if(!$checkYuyue){
            _apiReturn(0,'预约项目不存在~');
        }
        $type = I('yuyue') ? I('yuyue') : 'yuyue-game';
        $check = D('Sms')->check_code(I('mobile'),I('code'),$type);
        if($check == 0){
            _apiReturn(0,'验证码错误~');
        }
        if($check == -1){
            _apiReturn(0,'验证码已过期，请重新获~');
        }
        // 验证成功，需要写具体的了逻辑了
        $data = [
            'pid' => I('pid'),
            'mobile' => I('mobile'),
            'status' => 1,
            'create_time' => time(),
            'update_time' => time()
        ];
        $m = D('GameYuyueUser');
        if($m->add($data)){
            //新预约则删除缓存
            F('YUYUE_COUNT_'.I('pid'),NULL); //删除预约统计
            _apiReturn(1,'success');
        }else{
            _apiReturn(0,'预约失败~');
        }
    }

    /**
     * huhaiqin,2024.10.13
     * 检测预约是否已经完成
     * 根据pid，mobile查询
     */
    public function check_yuyue_done(){
        $check = D('GameYuyueUser')->_get_done(I('mobile'),I('pid'));
        $check ? _apiReturn(1,'success',$check) : _apiReturn(0,'no');
    }
}